#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define	SMPS_RD_CMD	0x80
#define	SMPS_WR_CMD	0x1A

#define MAGIC_NUMBER  'Q'
#define E522_U16_IOC_WR	_IOW(MAGIC_NUMBER, 0, int)
#define E522_U16_IOC_RD	_IOR(MAGIC_NUMBER, 1, int)
#define E522_IOC_MAXNR 2

#define device	"/dev/e52241"

char* ioctl_msg[E522_IOC_MAXNR] = {
	"E522_U16_IOC_WR",
	"E522_U16_IOC_RD"
};


int main(void)
{
	unsigned char ioctl_rdata;
	int fd,ret;
	struct msg
	{
		unsigned char addr;
		unsigned char data;
	};
	struct msg mymsg;
	/**open**/
	fd = open(device, O_RDWR);
	if(fd == -1){
		perror("open");
		exit(0);
	}

	/**write**/
	mymsg.addr=SMPS_WR_CMD;
	mymsg.data=0x01cd;
	ret = ioctl( fd, E522_U16_IOC_WR,&mymsg);
    	if(ret == -1)
    	{
    		perror("ioctl write");
     		exit(0);
    	}
	printf("ioctl write 0x%x ,0x%x \n",mymsg.addr,mymsg.data);
	
	/**read**/
	mymsg.addr=SMPS_RD_CMD;
	ret = ioctl( fd, E522_U16_IOC_RD,&mymsg);
    	if(ret == -1)
    	{
    		perror("ioctl read");
     		exit(0);
    	}
	printf("ioctl read 0x%x \n",mymsg.data);

	close(fd);
	
	return 0;
}
